const express = require('express');
const classmod = require('../module/class');
const  classrouter= express.Router();
classrouter.post('/add',(req,res)=>{
    let data = req.body;
    classmod.addClass(data,(data,classGuid)=>{
        res.send({status:1,data:'创建班级成功'});
    })
});
//获取班级列表
classrouter.get('',(req,res)=>{
    let classGuid = req.query.class_id;
    classmod.getClassList(classGuid, (data)=>{
             res.send({status:1,data:data});
        })
});
//根据Guid获取班级学生信息
classrouter.get('/studentList',(req,res)=>{
    let classGuid = req.query.fk_classId;
    if(!classGuid){
        res.send({status:0,err:'classGuid is required'});
    }else{
        classmod.getSudentList(classGuid, (data)=>{
            res.send({status:1,data:data});
        })
    }
});
//根据创建者去获取班级
classrouter.get('/classList',(req,res)=>{
   classmod.getClassListByUser(req.query.user_number,req.query.status,(data)=>{
        res.send({status:1,data});
   })
});
//删除班级
classrouter.put('',(req,res)=>{
   classmod.deleteClassList(req.query.classId,(data)=>{
        if(data.affectedRows==0){
            res.send({status:0,data:'删除班级失败'});
        }else {
            res.send({status:1,data:'删除班级成功'});
        }
   })
});
classrouter.post('/modify',(req,res)=>{
   classmod.modeifyClass(req.body,(data)=>{
       if(data.affectedRows==0){
           res.send({status:0,data:'修改班级失败'});
       }else {
           res.send({status:1,data:'修改班级成功'});
       }
   })
});
module.exports = classrouter;
